﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Meraz.Core.Model;

namespace Meraz.Core.Repositories
{
    public interface IUrlRepository : IRepository<Url, int>
    {
        Url Get(string name);
        List<Url> GetByDomain(string domainName);
    }
    public class UrlRepository : EFRepositoryBase<Url, int>, IUrlRepository
    {
        public UrlRepository() : base() { }
        public UrlRepository(Data.IMerazContext context) : base(context) { }
        public override Url GetById(int id)
        {
            return context.Urls
                .Where(where1 => where1.ID == id)
                .FirstOrDefault();
        }
        public List<Url> GetByDomain(string domainName)
        {
            return context.Urls
                .Where(where1 => where1.Domain.Name == domainName).ToList();
        }
        public Url Get(string href)
        {
            return context.Urls
                .Where(where1 => where1.Name == href)
                .FirstOrDefault();
        }

        public override void Add(Url entity)
        {
            context.Urls.AddObject(entity);
        }

        public override void Delete(Url entity)
        {
            context.Urls.DeleteObject(entity);
        }

        public override List<Url> All()
        {
            return context.Urls.ToList();
        }
    }
}
